﻿using System;
using System.Data;

namespace CRS.Web.BaseData
{
    public partial class ManifestList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            pgList.DataSourceDelegate=new VitCode.Web.UI.PaginationGrid.GridDataSourceDelegate(BindData);
            if (!IsPostBack)
            {
                Session["MainfestSource"] = null;
                Session["SelectedManifest"] = null;
                BindDrpList();
                pgList.BindGrid();
            }
        }

        private DataTable DataSource
        {
            get
            {
                if (Session["MainfestSource"] == null)
                {
                    Session["MainfestSource"] = InitData();
                }
                return (DataTable)Session["MainfestSource"];
            }
        }

        private object BindData()
        {
            return DataSource;
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("ManifestEdit.aspx");
        }

        protected void pgList_OnGridItemSelect(object sender, VitCode.Web.UI.PaginationGridItemSelectArgs e)
        {
            var dd = pgList.SelectedDataKeyValue;
            var selectedInfo = DataSource.Select("单号='" + pgList.SelectedDataKeyValue + "'");
            Session["SelectedManifest"] = selectedInfo;
            Response.Redirect("ManifestEdit.aspx?bill="+dd);
        }

        private void BindDrpList()
        {
        }

        private object InitData()
        {
            var table = new DataTable();
            table.Columns.Add("单号");
            table.Columns.Add("配货公司");
            table.Columns.Add("配货时间");
            table.Columns.Add("创建人");
            table.Columns.Add("创建时间");
            table.Columns.Add("状态");
            table.Columns.Add("备注");
            for(int i=0;i<20;i++)
            {
                var row = table.NewRow();
                row["单号"]="VIC_"+i.ToString().PadLeft(10,'0');
                row["配货公司"]="广东珠海百货";
                row["配货时间"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                row["创建人"]="张三"+i.ToString();
                row["创建时间"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                row["状态"] = "理货中";
                row["备注"]="用于Demo显示的数据";
                table.Rows.Add(row);
            }
            return table;
        }
    }
}
